package FIT::Fixture::Action;

use FIT::Class;
use FIT::TypeAdapter;
use aliased 'FIT::Util::ClassLoader';

extends 'FIT::Fixture::Base';

has actor => (is => 'rw', isa => 'Any');

augment do_cell => sub {};

after do_cells => sub {
    my $first_cell = shift;
    my $method     = $first_cell->fit_identifier;
    my $cell_2     = $first_cell->next_cell;
    $self->$method($cell_2->fit_identifier, $cell_2->next_cell);
};

sub start {
    my $class = shift;
    ClassLoader->load($class);
    $self->actor( $class->new );
    $self->actor->start;
}

sub enter {
    my ($field, $cell) = @_;
    $self->make_adapter($field)->parse_and_set($cell);
}

sub press {
    my $method = shift;
    $self->actor->$method;
}

sub check {
    my ($field, $cell) = @_;
    $self->make_adapter($field)->parse_and_check($cell);
}

sub make_adapter { adapt adaptee => $self->actor, name => shift }
